import React from 'react'
import './Pagination.scss'

export default function Pagination(props) {
  let pageSize = props.pageSize || 10
  let current = props.current || 1
  let total = props.total
  let lengtArr = Array.from({length: Math.ceil(total / pageSize)})
  const prePage = () => {
    props.change(current - 1)
  }
  const nextPage = () => {
     props.change(current + 1)
  }
  const clickNumber = (index) => {
    props.change(index)
  }
  return (
    <div className='Pagination'>
      {
        lengtArr.length > 0 && current !== 1 && <span className='prePage item' onClick={prePage}>上一页</span>
      }
      {
        total > 0 && lengtArr.map((_, index) => <span className={current === index + 1 ? 'active item' : 'item'} key={index}
          onClick={() => clickNumber(index + 1)}
        >{index + 1}</span>)
      }
      {
        lengtArr.length > 0 && current !== lengtArr.length && <span className='nextPage item'
          onClick={nextPage}
        >下一页</span>
      }
    </div>
  )
}
